﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Tanmia.Warehouse.Core;
using FluentNHibernate.Mapping;

namespace Tanmia.Warehouse.NHibernateRepository.Mapping
{
    public class StockMovementMap : ClassMap<StockMovement>
    {
        public StockMovementMap()
        {
            Table("StockMovement");

            Id(x => x.StockMovementID).Not.Nullable().GeneratedBy.Identity().Unique();
            Map(x => x.Quantity).Not.Nullable();
            Map(x => x.Price).Not.Nullable();
            Map(x => x.MovementDate).Not.Nullable();
            Map(x => x.MovedQuantity).Not.Nullable();

            References(x => x.Item, "ItemID").Not.Nullable();
            References(x => x.Store, "StoreID").Not.Nullable();

            Component(x => x.ItemUnit, m =>
            {
                m.Map(y => y.ItemUnitID);
                m.Map(y => y.Scale);
                m.References(y => y.Unit, "UnitID");
            });

            Component(x => x.ItemUnitPrice, m =>
            {
                m.Map(y => y.ItemUnitPriceID);
                m.Map(y => y.UnitPrice);
                m.References(y => y.PriceName, "PriceNameID");
            });

            HasMany<StockMovementDetail>(x => x.Details).KeyColumn("StockMovementID").Inverse();
        }
    }
}
